<?php
  /**
   * Elgg europass : Europass CV submary view
   * 
   * @package ElggEuropass
   * @link http://e-portfolio.uvsq.fr/
   */
  
  // Allows the header to know wether or not to load the fancybox javascript
  global $uvsq_browser;
  $uvsq_browser = true;
  global $uvsq_tabs;
  $uvsq_tabs = true;
  
  $profilePicJS = preg_replace("(\r\n|\n|\r)", "", elgg_view("profile/icon", array(
          'entity' => $vars['entity']->getOwnerEntity() ,
          'size' => 'small'
        )));
  
  global $uvsq_maps;
  $uvsq_maps = array($vars['entity']->municipality.','.$vars['entity']->postalCode, '<div class="blog_post_icon">'.$profilePicJS.'</div><p class="strapline">'.t($vars['entity']->firstname) . t($vars['entity']->lastname, ' ').'</p>');
  if (isset($vars['entity'])) {
?>

	<div class="blog_post">
		<h2>
      <?php echo $vars['entity']->title; ?>
    </h2>
		<!-- display the user icon -->
		<div class="blog_post_icon">
		  <?php
        echo elgg_view("profile/icon", array(
          'entity' => $vars['entity']->getOwnerEntity() ,
          'size' => 'tiny'
        ));
      ?>
    </div>
    <p class="strapline">
			<?php
        setlocale(LC_TIME, 'fr_FR.UTF-8');
        echo sprintf(elgg_echo("europass:strapline") ,
        //date("F j, Y",$vars['entity']->time_created)
        // tice@cri.uvsq.fr date change for french 11/03/2009
        strftime('%d %B %Y', $vars['entity']->time_created));
      ?>
		</p>
    <!-- display tags -->
    <p class="tags">
			<?php
        if ($vars['entity']->canEdit()) {
          echo elgg_view('output/eurotags', array(
            'tags' => $vars['entity']->tags,
            'euroGuid' => $vars['entity']->getGUID() ,
            'entity' => $vars['entity']
          ));
        }
        else {
          echo elgg_view('output/tags', array(
            'tags' => $vars['entity']->tags
          ));
        }
      ?>
    </p>
    <div class="clearfloat"></div>
    <div class="europass_post_body">
      <div id="example" class="flora">
        <ul id="pel_menu">
          <li><a href="#fragment-1"><span><?php echo elgg_echo('Résumé'); ?></span></a></li>
          <li><a href="#fragment-2"><span><?php echo elgg_echo('europass:education'); ?></span></a></li>
          <li><a href="#fragment-3"><span><?php echo elgg_echo('europass:language'); ?></span></a></li>
          <li><a href="#fragment-4"><span><?php echo elgg_echo('europass:skills'); ?></span></a></li>
          <li><a href="#fragment-5"><span><?php echo elgg_echo('CV PDF'); ?></span></a></li>
        </ul>
        <div id="fragment-1">
        <?php
          echo '<h4>' . elgg_echo('Identité') . '</h4>';
          echo t($vars['entity']->firstname) . t($vars['entity']->lastname, ' ', '<br />');
          echo t($vars['entity']->municipality) . t($vars['entity']->postalCode, ' (', ')<br />');
          echo t('<a href="' . $vars['url'] . 'mod/messages/send.php?send_to=' . $vars['entity']->getObjectOwnerGUID() . '">' . elgg_echo('europass:message') . '</a>');
          echo t($vars['entity']->application, '<h4>' . elgg_echo('europass:application') . '</h4>', '<br />');
        ?>
        <?php
          echo '<h4>' . elgg_echo('Géolocalisation') . '</h4>';
        ?>
          <div id="map_canvas" style="width: 100%; height: 300px"></div>
        </div>
        <div id="fragment-2">
        <?php
          if (is_array($vars['entity']->educationTitles)) {
            for ($i = 0; $i < count($vars['entity']->educationTitles); $i++) {
              echo t(ucfirst($vars['entity']->educationTitles[$i]), '<h4>', '</h4>');
              echo t('<em>' . ucfirst($vars['entity']->educationSkills[$i]) . '</em>', '<br />');
            }
          }
          else {
            echo t(ucfirst($vars['entity']->educationTitles) . '<br />');
            echo t('<em>' . ucfirst($vars['entity']->educationSkills) . '</em><br />');
          }
        ?>
        </div>
        <div id="fragment-3">
        <?php
          echo t($vars['entity']->motherLanguage, '<h4>' . elgg_echo('europass:motherLanguage') . '</h4>', '<br />');
          if (is_array($vars['entity']->foreignLanguages)) {
            echo '<h4>' . elgg_echo('europass:foreignLanguages') . '</h4>';
            for ($i = 0; $i < count($vars['entity']->foreignLanguages); $i++) {
              echo ucfirst($vars['entity']->foreignLanguages[$i]) . '<br />';
            }
          }
          else {
            echo ucfirst($vars['entity']->foreignLanguages) . '<br />';
          }
        ?>
        </div>
        <div id="fragment-4">
        <?php
          if (!empty($vars['entity']->skills) || !empty($vars['entity']->drivingLicences)) {
            echo '<h4>' . elgg_echo('europass:skills') . '</h4>';
            if (is_array($vars['entity']->skills)) {
              for ($i = 0; $i < count($vars['entity']->skills); $i++) {
                echo ucfirst($vars['entity']->skills[$i]) . '<br />';
              }
            }
            else {
              echo ucfirst($vars['entity']->skills) . '<br />';
            }
            if (is_array($vars['entity']->drivingLicences)) {
              echo '<h4>' . elgg_echo('europass:driving') . '</h4>';
              for ($i = 0; $i < count($vars['entity']->drivingLicences); $i++) {
                echo ucfirst($vars['entity']->drivingLicences[$i]);
                echo ($i < (count($vars['entity']->drivingLicences) - 1)) ? ', ' : '';
              }
            }
            else {
              echo '<h4>' . elgg_echo('europass:driving') . '</h4>';
              echo ucfirst($vars['entity']->drivingLicences);
            }
          }
        ?>
        </div>
        <div id="fragment-5">
          <?php if ($vars['entity']->canEdit() || $vars['entity']->export) : ?>
          <?php echo '<h4>' . elgg_echo('Télécharger le CV en PDF') . '</h4>'; ?>
          <div id="pdfCV">
            <a href="<?php echo $vars['url'] ?>action/europass/download?file_guid=<?php echo $vars['entity']->PDFfile ?>">
              <img src="<?php echo $vars['url'] ?>mod/file/graphics/icons/pdf.gif" />
            </a>
          </div>
          <?php endif ?>
          </div>
        </div>
      </div>    

    <div class="clearfloat"></div>
    <!-- display edit options if it is the CV owner -->
    <p class="options">
      <?php
        if ($vars['entity']->canEdit()) {
      ?>
      <a href="<?php echo $vars['url']; ?>mod/europass/edit.php">
        <?php echo elgg_echo("edit"); ?>
      </a>
      &nbsp; 
      <span id="euroPref">
        <a href="#prefBox" id="euroEditPref">
          <?php echo elgg_echo('europass:edit:pref') ?>
        </a>
      </span>
      <?php
        echo elgg_view("output/confirmlink", array(
          'href' => $vars['url'] . "action/europass/delete?guid=" . $vars['entity']->getGUID() ,
          'text' => elgg_echo('delete') ,
          'confirm' => elgg_echo('deleteconfirm') ,
        ));
        // Allow the menu to be extended
        echo elgg_view("editmenu", array(
          'entity' => $vars['entity']
        ));
      ?>
      <?php
        }
      ?>
    </p>
  </div>

<?php
  }
  
  
  function t($property, $before = '', $after = '')
  {
    if (!empty($property)) {
      return $before . ucfirst($property) . $after;
    } else return '';
  }
?>